﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlgorithmResult
{
     [Serializable]
    public class Result
    {
        public Result(long[] boundariesSet, String[] archreTriplets, int numOfBoundaries)
        {
            this.boundariesSet = boundariesSet;
            this.archreTriplets = archreTriplets;
            this.numOfBoundaries = numOfBoundaries;
          
        }
        public String Text { get; set; }
         public int[]  CodonSize   { get; set; }
        long[] boundariesSet;

        public long[] BoundariesSet
        {
            get { return boundariesSet; }
            set { boundariesSet = value; }
        }

        String[] archreTriplets;

        public String[] ArchreTriplets
        {
            get { return archreTriplets; }
            set { archreTriplets = value; }
        }

        int numOfBoundaries;

        public int NumOfBoundaries
        {
            get { return numOfBoundaries; }
            set { numOfBoundaries = value; }
        }

        float[] similarityToAncientCodon;

        public float[] SimilarityToAncientCodon
        {
            get { return similarityToAncientCodon; }
            set { similarityToAncientCodon = value; }
        }

        // the similarity of individual to ancient codons 
        float totalIndividualSimilarity;

        public float TotalIndividualSimilarity
        {
            get { return totalIndividualSimilarity; }
            set { totalIndividualSimilarity = value; }
        }

        private double genteticAggregationValue;


        public double GenteticAggregationValue
        {
            get { return genteticAggregationValue; }
            set { genteticAggregationValue = value; }
        }

        public double GetSimpleSimilarityValue()
        {
            double sumSimilarityResult = 0;

            for (int i = 0; i < numOfBoundaries - 1; i++)
            {
                sumSimilarityResult += Sim(archreTriplets[i], archreTriplets[i + 1]);
            }

            return sumSimilarityResult / numOfBoundaries;
        }


        private double Sim(String triplet1, String triplet2)
        {
            // the similaruty of triplets
            double simTriplets = 0;
            // 
            try
            {
                for (int i = 0; i < triplet1.Length; i++)
                {
                    if (triplet1[i].Equals(triplet2[i]))
                        simTriplets += 1; //(double)1 / triplet1.Length;
                }

                //for (int i = 0; i < CodonSize[archeCodonIndex]; i++)
                //{
                //    if (archreTriplets[triplet1_Index * CodonSize[archeCodonIndex] + i].Equals(archreTriplets[triplet2_Index * CodonSize[archeCodonIndex] + i]))
                //    {
                        
                //        simTriplets += ((double)1 / CodonSize[i]);
                //    }
                //}
            }
            catch (Exception)
            {

                System.Console.WriteLine("similarity error");
               // throw new ArgumentOutOfRangeException("sim error");
            }

            return simTriplets;
        }
    }
}
